package HCI.src;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.MediaController;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.VideoView;

public class register extends Activity// implements SurfaceHolder.Callback 
{      	Connector a;
	 Spinner SpinnerCountries;
	 ArrayAdapter<CharSequence> AdapterCountries;
	  public void onCreate(Bundle savedInstanceState) {
		  super.onCreate(savedInstanceState);
		   setContentView(R.layout.register);

		   String[] Countries = { "i cook every day  ", "i can cook but not good ", "i don t have experience with cooking" };

		   // //////////////////Countries Spinner/////////////////////////////////
		   SpinnerCountries = (Spinner) findViewById(R.id.Spinner01);

		   // //////////////////////////////////////////////////////////////
		   // create an arrayAdapter an assign it to the spinner
		   AdapterCountries = new ArrayAdapter<CharSequence>(this,
		   android.R.layout.simple_spinner_item);
		   AdapterCountries
		   .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		   SpinnerCountries.setAdapter(AdapterCountries);

		   int lenCountries = Countries.length;

		   for (int i = 0; i < lenCountries; i++) {
		   // test += Areas[i] + "\n";
		   AdapterCountries.add(Countries[i]);
		   }
		   Button register = (Button)findViewById(R.id.Done);
		    register.setOnClickListener(new View.OnClickListener(){
		    
		    	public void onClick(View view) {
		    		EditText username = (EditText)findViewById(R.id.UsernameReg);
	 		        EditText password = (EditText)findViewById(R.id.passwordReg);
		    	 if(username.getText().toString().equals("")|| password.getText().toString().equals("")){
	   		    		Toast.makeText(getBaseContext(), "sorry you have to enter character in the empty field or numbers or cobination of both  ", Toast.LENGTH_LONG).show();	

		    	 }
		    	 else{
     		        a=new Connector("INSERT INTO user (usr_name,usr_pswd,usr_exp) VALUES ("+"'"+username.getText()+"'"+","+"'"+password.getText()+"'"+","+1+")");
                   a.run();
                   
                   if(a.inserted==true){
                	   		    		Toast.makeText(getBaseContext(), "YOU ARE REGISTERED", Toast.LENGTH_LONG).show();	
		    		Intent switchToRegistration = new Intent(view.getContext(), Home.class);
					
					startActivity(switchToRegistration);
                   }
                   else{
	   		    		Toast.makeText(getBaseContext(), "Please enter another username", Toast.LENGTH_LONG).show();	

                   }
		    	}
		    }
		    }
		    	);
		  
	  }
	  
}